package codingforgreat.lchot150;

import sun.nio.cs.FastCharsetProvider;

public class Lc251 {
    //二维数组迭代器
    public static class Vector2D {
        int[][] maxtix;
        int row;
        int col;
        boolean curUse;
        public Vector2D(int[][] matrix) {
            this.maxtix = matrix;
            row = 0;
            col = -1;
            curUse = true;
        }
        public boolean hasNext() {
            if(row == maxtix.length){
                return false;
            }
            if(!curUse){
                return true;
            }
            if(col < maxtix[0].length - 1){
                col++;
            }else{
                col = 0;
                do{
                    row++;
                }while (row < maxtix.length && maxtix[row].length == 0);
            }
            // 新的(row，col)
            if (row != maxtix.length) {
                curUse = false;
                return true;
            } else {
                return false;
            }
        }
        public int next() {
        int ans = maxtix[row][col];
        curUse = true;
        hasNext();
        return  ans;

        }

    }
}
